package gwtool.gui.components;

import javax.swing.JComboBox;

public class ComboBoxWithChangeSupport extends JComboBox implements ChangeSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -301757752196190224L;

	private Object preSelectedObject = null;

	@Override
	public boolean hasChanged() {

		if (preSelectedObject == null) {
			if (getSelectedItem() == null) {
				return false;
			}
			return true;
		}
		Object selected = getSelectedItem();
		return !preSelectedObject.equals(selected);
	}

	@Override
	public void setChangedFalse() {

		preSelectedObject = getSelectedItem();
	}

	public void setPreSelectedItem(Object o) {

		preSelectedObject = o;
		super.setSelectedItem(o);
	}
}
